var http = axios.create({
  baseURL: '', //基础地址
  timeout: 3000, //超时时间
  headers: { //自定义请求头
    'Content-Type': 'application/json',
    'SC-Token': 'eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIyOSIsImF1ZCI6InRlc3QiLCJpYXQiOjE2MDAxNDEwNjQsInJvbGVzIjoiNCIsImV4cCI6MTk2MDE0MTA2NH0.g4_mSdEy6HhKmK8khunqaBxZmipFoaPdip6ur8H72Jk'
  }
});

//request 请求之前拦截
http.interceptors.request.use(function(config){

  return config;

}, error);

//response 响应之后拦截
http.interceptors.response.use(function(response){
  
  return response.data;

}, error );


//公共错误处理函数
function error( err ){
  
  if(/Network(.*)Error/gi.test(err)){
    alert('请检查网络连接！');
  }else if (err.response) {
    const { status } = err.response;
    if (status === 401) {
      alert('访问被拒绝');
    }else if (status === 403) {
      alert('资源不可用');
    }else if (status === 404) {
      alert('找不到页面');
    }else if (status === 405) {
      alert('不允许此方法');
    }else if (status === 500) {
      alert('服务内部错误');
    }else{
      alert('未知错误');
    }
    return Promise.reject( err );
  }
}